<template>
    <div>
        <h1>房号添加</h1>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td>房型</td>
                    <td><select v-model="queryinfo.houseTypeName">
                            <option value="">请选择</option>
                            <option :value="item.houseTypeName" v-for="item in houseTypeList">{{ item.houseTypeName }}
                            </option>
                        </select></td>
                </tr>
                <tr>
                    <td>房号</td>
                    <td><input type="text" v-model="queryinfo.houseNumbers"></td>
                </tr>
                <tr>
                    <td>房号备注</td>
                    <td><input type="text" v-model="queryinfo.desc"></td>
                </tr>
                <tr>
                    <td>状态</td>
                    <td>
                        <input type="radio" name="state" value="1" v-model="queryinfo.state">上架
                        <input type="radio" name="state" value="0" v-model="queryinfo.state">下架
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td><input type="button" value="添加" @click="OK()"></td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref, reactive, onMounted } from 'vue';
import moment from 'moment';
import { useRoute, useRouter } from 'vue-router';
const route = useRoute();
const router = useRouter();

onMounted(() => {
    gethouseTypeList();
})

let queryinfo: any = reactive({
    "houseTypeName": "",
    "houseNumbers": "",
    "desc": "",
    "state": '',
})

let houseTypeList: any = ref([]);
const gethouseTypeList = () => {
    axios({
        url: '/api/House/GetHouseTypes',
        method: 'get',
    })
        .then(res => {
            houseTypeList.value = res.data;
        })
        .catch(err => {

        })
}
const OK = () => {
    axios({
        url: '/api/House/AddHouseNumber',
        method: 'post',
        data: queryinfo,
    })
        .then(res => {
            if (res.data == -1) {
                alert("房号不能重复");
                return;
            }
            if (res.data > 0) {
                alert("添加成功");
                router.push('/houseNumberList');
                return;
            }
            else {
                alert("添加失败");
                return;
            }
        })
        .catch(err => {

        })
}
</script>

<style scoped></style>